package cau.se.project.unittest;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import cau.se.project.data.DSMRow;
import cau.se.project.data.DependencyStructureMatrix;
import cau.se.project.data.method.RowControl;

import static org.hamcrest.CoreMatchers.is;

public class DependencyStructureMatrixTest {
	private DependencyStructureMatrix dsm;
	private RowControl dsmRow;
	private RowControl otherRow;
	
	@Before
	public void setUp() throws Exception {
		this.dsm = new DependencyStructureMatrix();
		this.dsmRow = new DSMRow("TestRow");
		otherRow = new DSMRow("otherRow");
	}

	@Test
	public void testMakeRow() {
		assertThat(this.dsm.makeRow("TestRow").getName(), is(dsmRow.getName()));
	}
	
	@Test
	public void testRemoveRow() {
		this.dsm.insertRow(dsmRow, null);
		
		assertThat(this.dsm.getRow(0), is(dsmRow));

		this.dsm.removeRow(dsmRow);
		
		assertNull(this.dsm.getRow(0));
	}

	@Test
	public void testInsertRow() {
		assertNull(this.dsm.getRow(0));
		
		this.dsm.insertRow(dsmRow, null);
		
		assertThat(this.dsm.getRow(0), is(dsmRow));
		
		this.dsm.insertRow(otherRow, dsmRow);
		
		assertThat(this.dsm.getRow(0), is(otherRow));
	}

	@Test
	public void testToArray() {
		assertThat(this.dsm.toArray(), is(new int[][] {}));
		
		this.dsm.insertRow(dsmRow, null);
		
		assertThat(this.dsm.toArray(), is(new int[][] {{0}}));
		
		this.dsm.insertRow(otherRow, null);
		
		assertThat(this.dsm.toArray(), is(new int[][] {{0, 0}, {0, 0}}));
	}

	@Test
	public void testGetSize() {
		assertThat(this.dsm.getSize(), is(0));
		
		this.dsm.insertRow(dsmRow, null);
		
		assertThat(this.dsm.getSize(), is(1));
	}

	@Test
	public void testGetRow() {
		assertNull(this.dsm.getRow(0));
		
		this.dsm.insertRow(dsmRow, null);
		
		assertThat(this.dsm.getRow(0), is(dsmRow));
	}

	@Test
	public void testFindRowByName() {
		assertNull(this.dsm.findRowByName("TestRow"));
		
		this.dsm.insertRow(dsmRow, null);

		assertThat(this.dsm.findRowByName("TestRow"), is(dsmRow));
	}
}
